#include "namepipe.hpp"
#include "log.hpp"
int main()
{
    InitNamePipe init;
    Log log;
    //等待写端打开时候会堵塞（只有读端）
    int rfd = open(PIPENAME,O_RDONLY);
    if(rfd < 0)
    {
        log(FATAL, "error string: %s, error code: %d", strerror(errno), errno);
        exit(FIFO_OPEN_ERR);
    }
    cout<<"server is ready"<<endl;

    char rbuffer[BUFFERSIZE];
    while(true)
    {
        int readRet = read(rfd,rbuffer,sizeof(rbuffer));
        if(readRet <= 0)
        {
            log(DEBUG, "client quit, me too!, error string: %s, error code: %d", strerror(errno), errno);
            break;
        }
        rbuffer[readRet] = 0;
        cout << rbuffer << endl;
    }
    return 0;
}